package com.lq.schoolshop.dao;

import com.lq.schoolshop.pojo.Goods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author
 * @Date2021/1/7 10:24
 * @Version V1.0
 * 商品接口
 **/
public interface GoodsMapper {

    //查询全部商品  根据排序号 进行排序
    @Select("SELECT id,NAME,COUNT,FORMAT(price,2) AS price,image,sort,storeid,sellcount,detail,recommend,href,descript FROM goods ORDER BY sort DESC")
    List<Goods>selByall();

    //根据商品名模糊查询       1:广告  -1:不是广告
    @Select("SELECT * FROM goods WHERE NAME LIKE CONCAT('%',#{name} ,'%') AND recommend>0 ORDER BY sort DESC")
    List<Goods>selByName(@Param("name") String name);

    //查询商品总条数
    @Select("SELECT COUNT(*) FROM goods")
    int countByTotal();

    //根据店铺ID查找该店铺下的所有商品
    @Select("SELECT * FROM goods WHERE storeid=#{storeid} ORDER BY sort DESC")
    List<Goods>selByStoreid(int storeid);

    //根据商品ID查询所属的商品以及所属店铺的信息
    @Select("SELECT * FROM goods WHERE id = #{id}")
    List<Goods>selById(@Param("id") int id);

    //根据商品ID查询商品数量
    @Select("SELECT COUNT FROM goods WHERE id = #{id}")
    int selCountById(int id);


}
